<!-- 物流线路 - 表单编辑页面 -->
<template>
  <div class="page_rela_container" >
		<div class="scroll_auto flex_cell">

    <!-- <page_breadcrumb /> -->

    <el-form ref="form" :model="form" :label-width="$globalCss.formLabelWidth_default" class="common-form-panel-div"
      style="min-width: 1240px;" v-loading="loading" :rules="formRules">

      <ex_header_spiler :title="$t('label_base_info')"></ex_header_spiler>

      <el-form-item :label="$t('label_line_name')" class="mg_t2" prop="tmsLineInfoParam.lineName">
        <ex_super_input v-model="form.tmsLineInfoParam.lineName" class="form_input_small"></ex_super_input>
      </el-form-item>


      <el-form-item :label="$t('label_origin')" prop="tmsLineInfoParam.originPlaceId">

        <template>
          <ex_super_input v-model="form.tmsLineInfoParam.originCountryCode" class="form_input_small" type='select' :attrs="{
            url: '/tms-api/base/TmsCountryRpc/selectCountry.json',
            filterable: true, urlParams: { typeEnum: 'LINE_AREA' },
            option: { label: it => $formatNameCode(it.countryName, it.countryCode), value: 'countryCode' }
          }" @changeItem="e => {
              form.tmsLineInfoParam.originCountryName = e ? e.countryName : '';
              form.tmsLineInfoParam.originCountryType = e.tmsCountryType
              }
          " />

<!--          :tms-country-type="form.tmsLineInfoParam.originCountryType"-->
          <place_select :value="form.tmsLineInfoParam.originPlaceId" class="form_input_small"
            :countryCode="form.tmsLineInfoParam.originCountryCode"
                        typeEnum="LINE_AREA,COMPREHENSIVE_POINT"
            @changeItem="changeOriginPlace" />
          <el-button @click="$refs.transportAreaOrigin.show()">{{ $t('label_logistics_division_config') }}
          </el-button>
        </template>


        <transport-area-edit ref="transportAreaOrigin" :areaIds="form.tmsLineInfoParam.originAreaIds"
          :countryCode="form.tmsLineInfoParam.originCountryCode" :countryName="form.tmsLineInfoParam.originCountryName"
          @afterSubmitSuccess="list => form.tmsLineInfoParam.originAreaIds = list.map(it => it.id)"></transport-area-edit>

      </el-form-item>

      <el-form-item :label="$t('label_destination')" prop="tmsLineInfoParam.destinationPlaceId">

        <template>

          <ex_super_input v-model="form.tmsLineInfoParam.destinationCountryCode" class="form_input_small" type='select'
            :attrs="{
              url: '/tms-api/base/TmsCountryRpc/selectCountry.json',
              filterable: true, urlParams: { typeEnum: 'LINE_AREA' },
              option: { label: it => $formatNameCode(it.countryName, it.countryCode), value: 'countryCode' }
            }" @changeItem="e =>
            {
              form.tmsLineInfoParam.destinationCountryName = e ? e.countryName : '';
              form.tmsLineInfoParam.destinationCountryType = e.tmsCountryType
            }
            "/>
          <!--  :tms-country-type="form.tmsLineInfoParam.destinationCountryType"-->
          <place_select v-model="form.tmsLineInfoParam.destinationPlaceId" class="form_input_small"
            :countryCode="form.tmsLineInfoParam.destinationCountryCode"
            :tmsCountryType="form.tmsLineInfoParam.destinationCountryType"
                        typeEnum="LINE_AREA,COMPREHENSIVE_POINT"
            @changeItem="changeDestinationPlace" />

          <el-button @click="$refs.transportAreaDestination.show()">{{ $t('label_logistics_division_config') }}

          </el-button>
        </template>
        <transport-area-edit ref="transportAreaDestination" :areaIds="form.tmsLineInfoParam.destAreaIds"
          :countryCode="form.tmsLineInfoParam.destinationCountryCode"
          :countryName="form.tmsLineInfoParam.destinationCountryName"
          @afterSubmitSuccess="list => form.tmsLineInfoParam.destAreaIds = list.map(it => it.id)"></transport-area-edit>


      </el-form-item>

      <el-form-item :label="$t('label_pms_product_type')" prop="tmsLineInfoParam.productType">
        <ex_super_input v-model="form.tmsLineInfoParam.productType" class="form_input_small" type='select' enum="PmsProductTypeEnum" :listHandler="list => list.filter(it => ['FIRST_TRANSPORT','LAST_TRANSPORT','EXPRESS'].includes(it) )" />
      </el-form-item>


      <ex_header_spiler :title="$t('label_route_option')"></ex_header_spiler>

      <div style="position: relative;">
        <div style="position: absolute; top: 4px; right: 0px; z-index: 100;">
          <el-button type="text" @click="addRoute" size="medium" icon="el-icon-plus">{{
            $t('label_tms_add_route') }}</el-button>
        </div>
        <el-tabs v-model="activeName" @tab-click="handleTabClick">

          <el-tab-pane v-for="route, routeIndex in form.routeAndSectionDTOList" :label="route.routeName"
            :key="'route_id_' + routeIndex" :name="String(routeIndex)">

            <el-form ref="formRoute" :model="route" :label-width="$globalCss.formLabelWidth_default"
              style="margin-top: 18px;" :rules="formRulesRoute">
              <el-form-item :label="$t('label_pms_main_transport_type')" prop="trunkLineMode">
                <div class="flex_row_center">

                  <ex_super_input :value="route.trunkLineMode" type="radio-group" enum="LogisticsProductsTypeEnum"
                    :button="true" class="flex_cell" @input="e => changeTrunkLineMode(route, e)" />
                  <el-button type="text" class='button_text_danger'
                    @click="removeRoute(form.routeAndSectionDTOList, routeIndex)" size="medium" icon="el-icon-remove">{{
                      $t('label_tms_line_delete_route') }}</el-button>
                </div>
              </el-form-item>

              <el-form-item :label="$t('label_tms_line_route_name')" prop="routeName">

                <el-input v-model="route.routeName" class="form_input_default"></el-input>
              </el-form-item>

              <el-form-item :label="$t('label_srm_transport_supported_packaging')" prop="isSustainMany">

                <template>
                  <el-checkbox disabled :value="true">{{ $t('label_srm_transport_one_one') }}</el-checkbox>
                  <ex_checkbox_yn :label="$t('label_srm_transport_one_more')" v-model="route.isSustainMany" />
                </template>

              </el-form-item>

              <el-form-item :label="$t('label_tms_path_point_config')" prop="createOrUpdateRouteSectionDTOList">
                <div class="manage-path-point-row">
                  <div class="manage-path-point-address cursor_pointer flex_col_center"
                    v-if="form.tmsLineInfoParam.originPlaceId">
                    {{ form.tmsLineInfoParam.originPlaceName }}
                    <div class="manage-path-point-desc">
                      <span>{{ $t('label_origin') }}</span>
                    </div>
                  </div>
                  <div style="display: flex;">
                    <div class="manage-path-point-line"></div>
                    <div class="manage-path-point-arrow"></div>
                  </div>
                  <template v-for="item, index in route.createOrUpdateRouteSectionDTOList">
                    <div class="manage-path-point-address cursor_pointer flex_col_center"
                      @mouseover="$set(item, 'showRemove', true)" @mouseleave="$set(item, 'showRemove', false)">
                      {{ item.placeName }}
                      <i v-show="item.showRemove" @click="removeRouteSection(route, index)" class="el-icon-remove"
                        style="position: absolute; top: 0px; right: 0px; cursor: pointer; color: #d74343; "></i>
                    </div>
                    <template>
                      <div style="display: flex;">
                        <div class="manage-path-point-line"></div>
                        <div class="manage-path-point-arrow"></div>
                      </div>
                    </template>
                  </template>
                  <div class="manage-path-point-address cursor_pointer flex_col_center"
                    v-if="form.tmsLineInfoParam.destinationPlaceId">
                    {{ form.tmsLineInfoParam.destinationPlaceName }}
                    <div class="manage-path-point-desc">
                      <span>{{ $t('label_destination') }}</span>
                    </div>
                  </div>
                </div>
              </el-form-item>

              <el-form-item>


                <ex_super_input v-model="tempCountryCode" class="form_input_small" type='select' :attrs="{
                  url: '/tms-api/base/TmsPlaceInfoRpc/selectCountry.json',

                  filterable: true,
                  option: { label: it => $formatNameCode(it.countryName, it.countryCode), value: 'countryCode' }
                }" />
                <ex_super_input v-model="tempPlaceType" class="form_input_mini" type='select' :attrs="{
                  enum: 'PlaceTypeEnum',
                  listHandler: (list) => {
                    list = list.filter(e => e != 'LINE_AREA')
                    list.splice(0, 0, 'ALL')
                    return list
                  }
                }" />

                <place_select v-model="tempPlaceId" class="form_input_small" :countryCode="tempCountryCode"
                  :typeEnum="tempPlaceType" @changeItem="e => tempPlace = e ? e : null" />

                <el-button class="el-icon-plus" @click="addRouteSection(route)">{{ $t('label_tms_add_path_point')
                }}</el-button>
              </el-form-item>




              <!-- 运营方案 -->
              <template v-for="scheme, schemeIndex in route.createAndUpdateOperationSchemeInfoList">
                <div class="flex_row_center ">
                  <div class="flex_cell"
                    style="margin-top: 10px; padding: 0px 0px 0px 20px; color: #409EFF; font-weight: bold; ">
                    {{ $t('label_tms_line_operation_project') }}{{ schemeIndex + 1 }}</div>
                  <el-button type="text" class="button_text_danger"
                    @click="route.createAndUpdateOperationSchemeInfoList.splice(schemeIndex, 1)" size="medium"
                    icon="el-icon-remove">{{ $t('label_tms_line_del_operation_project') }}</el-button>
                </div>

                <scheme_edit ref="formRouteScheme" :scheme="scheme" :prescription="form.tmsLineInfoParam.prescription"
                  :routeSection="listRouteSection(route)" :originCountryCode="form.tmsLineInfoParam.originCountryCode"
                  :destinationCountryCode="form.tmsLineInfoParam.destinationCountryCode" />


              </template>

              <el-form-item label="">
                <el-button type="text" size="medium" icon="el-icon-plus" @click="addScheme(route)">{{
                  $t('label_tms_line_add_operation_project') }}</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>

        </el-tabs>
      </div>

    </el-form>

  </div>
    <div class="page_rela_bottom_area">
      <el-button type="primary" @click="submit" :loading="submiting" :disabled="submiting">{{ $t('label_submit')
      }}</el-button>
      <el-button @click="return_page_back">{{ $t('label_fms_account_config_cancel') }}</el-button>
    </div>


  </div>
</template>
<script>

import LinePriceCfg from '@/component/pms/transport_price_cfg.vue'

import TransportAreaEdit from '@/component/pms/transport-area-edit.vue'

import place_select from '@/component/tms/place_select'

import scheme_edit from '@/component/tms/scheme_edit'

const default_scheme_info = {
  segmentSort: 0,//	integer 	路由段排序
  carrierId: null,//	long 	承运商id
  carrierName: "",//	string 	承运商名称
  transportSection: "",//	TransportSectionEnum 	运输段（提货: PICK_UP_GOODS 提货, TRUNK_LINE 干线, DISTRIBUTION 配送
  transportModel: "",//	LogisticsProductsTypeEnum 	运输模式（海运、空运、铁运、陆运、国际快递）: SEA_TRANSPORT 海运, SKY_TRANSPORT 空运, LORRY_NAVIGATE 陆运, INTERNATIONAL_EXPRESS 国际快递, IRON_TRANSPORT 铁运
  serviceItemList: "",//	string 	增值服务项（每个服务之间使用“,”分割）
  loadingMode: "BULK_CARGO",//	LoadingModeEnum 	装载方式(散货、整箱，整车): BULK_CARGO 散货, FULL_CONTAINER 整箱, COMPLETE_VEHICLE 整车
  prescription: 0,//	integer 	运输时效
  originPlaceId: null,//	long 	起点地点id
  destinationPlaceId: null,//	long 	终点地点id
}
const default_scheme = {
  "schemeName": "",
  "outPortId": "",
  "outPortName": "",
  "entryPortId": "",
  "entryPortName": "",
  "remark": "",
  transportSegmentInfoParamList: []
}
const default_route =
{
  "routeOwner": "SELF_SUPPORT",//LineOwnerEnum 线路所属（自营/第三方）: SELF_SUPPORT 自营, THIRD_PARTY 第三方
  "routeName": "陆运专线",
  routeNumber: 0,
  trunkLineMode: 'LORRY_NAVIGATE',//LogisticsProductsTypeEnum
  isSustainMany: 'N',
  createOrUpdateRouteSectionDTOList: [],
  "createAndUpdateOperationSchemeInfoList": []
}

const default_obj = {
  //线路信息
  "tmsLineInfoParam": {
    "lineName": "",//线路名称
    "lineOwner": "SELF_SUPPORT",//LineOwnerEnum 线路所属（自营/第三方）: SELF_SUPPORT 自营, THIRD_PARTY 第三方
    "prescription": 0,
    originCountryName: null,
    originCountryCode: null,
    originCountryType: null,
    destinationCountryName: null,
    destinationCountryCode: null,
    destinationCountryType: null,
    originAreaIds: [],
    destAreaIds: [],
    originPlaceId: null,
    originPlaceName: "",
    destinationPlaceId: null,
    destinationPlaceName: "",
    "minWeight": null,
    "maxWeight": null,
    "minVolume": null,
    "maxVolume": null,
    "maxBorder": null,
    "expression": null,
    ruleType: 'SIMPLE',//PmsTransportRuleTypeEnum 限制的校验方式: SIMPLE 简单校验模式, EXPRESSION 表达式模式
    productType:''//产品类型
  },
  "routeAndSectionDTOList": [],
}
import router_params from '@/mixin/router_params';
export default {
  components: { place_select, scheme_edit, LinePriceCfg, TransportAreaEdit },
  mixins: [router_params],

  data() {


    return {
      edit: false,
      detail: false,
      tempCountryCode: null,
      tempPlaceType: null,
      tempPlaceId: null,
      tempPlace: null,

      loading: false,
      submiting: false,

      form: _.cloneDeep(default_obj),
      formRules: {
        "tmsLineInfoParam.productType":{ required: true, message: this.$t('tip_can_no_empty'), trigger: 'blur' },
        "tmsLineInfoParam.lineName": { required: true, message: this.$t('tip_can_no_empty'), trigger: 'blur' },
        "tmsLineInfoParam.originPlaceId": {
          required: true, trigger: 'blur',
          validator: (r, v, cb) => {
            if (_.isEmpty(v)) {
              return cb(this.$t('tip_can_no_empty'))
            }
            if (v == this.form.tmsLineInfoParam.destinationPlaceId) {
              return cb(this.$t('tip_origin_and_destination_no_some'))
            }
            cb()
          }
        },
        "tmsLineInfoParam.destinationPlaceId": {
          required: true, trigger: 'blur',
          validator: (r, v, cb) => {
            if (_.isEmpty(v)) {
              return cb(this.$t('tip_can_no_empty'))
            }
            if (v == this.form.tmsLineInfoParam.originPlaceId) {
              return cb(this.$t('tip_origin_and_destination_no_some'))
            }
            cb()
          }
        },
        "tmsLineInfoParam.prescription": {
          required: true, trigger: 'blur', validator: (r, v, cb) => {
            !this.$reg.PureNumberLetter(v) ? cb(this.$t('tip_only_positive_pure_decimal')) : cb()
          }
        },
      },
      formRulesRoute: {

        "trunkLineMode": { required: true, message: this.$t('tip_can_no_empty'), trigger: 'blur' },
        "routeName": { required: true, message: this.$t('tip_can_no_empty'), trigger: 'blur' },
        isSustainMany: { required: true, message: this.$t('tip_can_no_empty'), trigger: 'blur' },

      },
      formRulesRouteScheme: {
        schemeName: { required: true, message: this.$t('tip_can_no_empty'), trigger: 'blur' },
        transportSegmentInfoParamList: {
          required: true,
          type: "array",
          trigger: 'change',
          validator: (r, v, cb) => {
            if (v.length <= 0) {
              return cb(this.$t('至少需要1个运输段'))
            }
            if (v.some(it => !it.transportSection)) {
              return cb(this.$t('请选择运输段类型'))
            }
            if (v.some(it => !it.transportModel)) {
              return cb(this.$t('请选择运输模式'))
            }
            if (v.some(it => !it.carrierId)) {
              return cb(this.$t('请选择服务商匹配'))
            }
            if (v.some(it => !this.$reg.PureNumberLetter(it.prescription))) {
              return cb("运输时效" + this.$t('tip_only_positive_pure_decimal'))
            }
            if (_.reduce(v, (r, it) => this.$math_add(r, Number(it.prescription)), 0) > Number(this.form.tmsLineInfoParam.prescription)) {
              return cb("运输段时效不能大于总运输时效")
            }
            cb()
          }
        },
      },
      "activeName": "0",




    };
  },


  methods: {
    enableOrDisable(type, item) {
      let url = ""
      if (type == 'line') {
        url = '/tms-api/base/TmsLineInfoRpc/enableOrDisable.json'
      } else if (type == 'route') {
        url = '/tms-api/base/TmsRouteInfoRpc/enableOrDisable.json'
      } else {
        url = '/tms-api/base/TmsOperationSchemeInfoRpc/enableOrDisable.json'
      }
      let status = item.status == 'ENABLE' ? 'DISABLED' : 'ENABLE'
      this.$confirm(status == 'ENABLE' ? this.$t('text_confirm_sure_start_using_operate') : this.$t('text_confirm_sure_stop_using_operate'), this.$t('label_tip'), {
        type: 'warning'
      }).then(() => {
        this.$ajax({
          url,
          method: 'post',
          data: { id: item.id, status: item.status == 'ENABLE' ? 'DISABLED' : 'ENABLE' },
          loading: true,
          success: (res) => {
            this.$message.success(this.$t('tip_submit_success'))
            this.refresh_data()
          }
        })
      }).catch(() => {

      });

    },
    init_data_default(into_params) {

      this.form = _.cloneDeep(default_obj)
      this.edit = !!into_params.edit
      if (this.edit) {
        if (into_params.id) {
          this.loading = true
          this.$ajax({
            url: "/tms-api/base/TmsLogisticsLineRpc/selectLogisticsLineByLineId.json",
            method: 'post',
            data: { lineId: into_params.id },
            success: (res) => {
              this.loading = false
              this.fixGetData(res.data)
              this.form = Object.assign(_.cloneDeep(default_obj), res.data)



              this.fixTabLabel()
            }
          })
        }

      } else if (_.isEmpty(this.form.routeAndSectionDTOList)) {


        this.addScheme(this.addRoute())
      }
      this.fixTabLabel()
    },
    fixTabLabel() {
      if (this.edit) {

        this.$emit('tagModifyLabel', {
          _key: "label_edit_logistics_route",
          code: this.form.tmsLineInfoParam.lineName || ""
        })
      } else {
        this.$emit('tagModifyLabel', "label_add_logistics_route")
      }
    },
    addRoute() {
      let route = _.cloneDeep(default_route)
      this.form.routeAndSectionDTOList.push(route)
      this.activeName = String(this.form.routeAndSectionDTOList.length - 1)
      return route
    },
    changeTrunkLineMode(route, e) {
      route.trunkLineMode = e
      this.refreshRouteSectionTrunk(route)

    },

    changeOriginPlace(item) {
      this.form.tmsLineInfoParam.originPlaceId = item ? item.id : null
      this.form.tmsLineInfoParam.originPlaceName = item ? item.placeName : null
      this.form.tmsLineInfoParam.origin = item
      this.form.routeAndSectionDTOList.forEach(route => {
        this.refreshRouteSection(route)
      })
    },
    changeDestinationPlace(item) {
      this.form.tmsLineInfoParam.destinationPlaceId = item ? item.id : null
      this.form.tmsLineInfoParam.destinationPlaceName = item ? item.placeName : null
      this.form.tmsLineInfoParam.destination = item
      this.form.routeAndSectionDTOList.forEach(route => {
        this.refreshRouteSection(route)
      })
    },
    addRouteSection(route) {
      if (this.form.tmsLineInfoParam.originPlaceId == null || this.form.tmsLineInfoParam.destinationPlaceId == null) {
        return this.$message.warning(this.$t("请先选择起点与终点"))
      }
      if (!this.tempPlace) return this.$message.warning(this.$t("tip_please_select_place"))
      if (route) {
        // const place = _.cloneDeep(this.tempPlace)
        // place.placeId = place.id
        // delete place.id

        if (this.listRouteSection(route).some(it => it.placeId == this.tempPlace.placeId)) {
          return this.$message.warning(this.$t("不能添加重复地点"))
        }
        const place = _.cloneDeep(this.tempPlace)
        place.placeId = place.id
        route.createOrUpdateRouteSectionDTOList.push(place)
      }
      this.tempPlace = null
      this.tempPlaceType = null

      this.refreshRouteSection(route)
    },
    removeRouteSection(route, index) {
      if (route) {
        route.createOrUpdateRouteSectionDTOList.splice(index, 1)
      }
      this.refreshRouteSection(route)
    },
    listRouteSection(route) {
      if (this.form.tmsLineInfoParam.originPlaceId == null || this.form.tmsLineInfoParam.destinationPlaceId == null) {
        return []
      }
      return [{
        placeId: this.form.tmsLineInfoParam.originPlaceId,
        placeName: this.form.tmsLineInfoParam.originPlaceName,
        ...this.form.tmsLineInfoParam.origin
      },
      ...route.createOrUpdateRouteSectionDTOList,
      {
        placeId: this.form.tmsLineInfoParam.destinationPlaceId,
         placeName: this.form.tmsLineInfoParam.destinationPlaceName,
         ...this.form.tmsLineInfoParam.destination
      },]
    },
    refreshRouteSection(route) {
      const routeList = this.listRouteSection(route)//oute.createOrUpdateRouteSectionDTOList
      routeList.forEach((it, i) => it.sort = i + 1)
      route.createAndUpdateOperationSchemeInfoList.forEach(scheme => {
        let newSegment = []

        for (let i = 0; i < routeList.length - 1; i++) {
          const originPlace = routeList[i]
          const destinationPlace = routeList[i + 1]
          let segmentItem = null
          if (i < scheme.transportSegmentInfoParamList.length) {
            segmentItem = scheme.transportSegmentInfoParamList[i]
          } else {
            segmentItem = _.cloneDeep(default_scheme_info)
            // segmentItem.transportModel = route.trunkLineMode
          }
          segmentItem.segmentSort = i + 1
          segmentItem.originPlaceId = originPlace.placeId
          segmentItem.destinationPlaceId = destinationPlace.placeId
          newSegment.push(segmentItem)
        }

        scheme.transportSegmentInfoParamList = newSegment
      })

      this.refreshRouteSectionTrunk(route)
    },
    changeTransportSection(e, item, route) {
      if (e == "TRUNK_LINE") {
        item.transportModel = route.trunkLineMode
      } else if (e == "DISTRIBUTION" || e == "PICK_UP_GOODS") {
        item.transportModel = "LORRY_NAVIGATE"
      } else {
        item.transportModel = null
      }
    },
    refreshRouteSectionTrunk(route) {
      route.createAndUpdateOperationSchemeInfoList.forEach(scheme => {
        for (let i = 0; i < scheme.transportSegmentInfoParamList.length; i++) {
          let item = scheme.transportSegmentInfoParamList[i]
          if (i == 0) {
            item.transportModel = "LORRY_NAVIGATE"
            item.transportSection = "PICK_UP_GOODS"
          } else {
            this.changeTransportSection(item.transportSection, item, route)
          }
        }
      })
    },
    removeRoute(list, i) {
      this.form.routeAndSectionDTOList.splice(i, 1)
      if (this.form.routeAndSectionDTOList.length > 0) {
        this.activeName = String(0)
      }
    },

    addScheme(route) {
      route.createAndUpdateOperationSchemeInfoList.push(_.cloneDeep(default_scheme))
      this.refreshRouteSection(route)
    },
    handleTabClick() {

    },
    submit: _.throttle(function (item) {
      this.submitForm()
    }, 700),
    submitForm() {

      let formRouteNoCheck = false
      if (this['$refs']['form']) {
        this['$refs']['form'].validate((valid) => {
          if (!valid) {
            formRouteNoCheck = true
          }
        });
      }

      if (this['$refs']['formRoute']) {
        this['$refs']['formRoute'].forEach(formRoute => {
          formRoute.validate((formRoutevalid) => {
            if (!formRoutevalid) {
              formRouteNoCheck = true
            }
          });
        })
      }
      if (this['$refs']['formRouteScheme']) {
        this['$refs']['formRouteScheme'].forEach(formScheme => {
          formScheme.validate((formSchemevalid) => {
            if (!formSchemevalid) {
              formRouteNoCheck = true
            }
          });
        })
      }


      if (formRouteNoCheck) {
        this.$message.error(this.$t('form_validate_error'))
      } else {

        this.submitNet()
      }

    },

    submitNet() {

      if (this.form.tmsLineInfoParam.id) {
        this.updateRemote()
      } else {
        this.saveRemote()
      }
    },
    fixGetData(data) {
      data.routeAndSectionDTOList.forEach(route => {
        let originIndex = _.findIndex(route.createOrUpdateRouteSectionDTOList, it => it.placeId == data.tmsLineInfoParam.originPlaceId)

        if (originIndex >= 0) {
          route.createOrUpdateRouteSectionDTOList.splice(originIndex, 1)
        }

        let destinationIndex = _.findIndex(route.createOrUpdateRouteSectionDTOList, it => it.placeId == data.tmsLineInfoParam.destinationPlaceId)
        if (destinationIndex >= 0) {
          route.createOrUpdateRouteSectionDTOList.splice(destinationIndex, 1)
        }

      })
    },

    fixSubmitData(data) {
      data.routeAndSectionDTOList.forEach(route => {
        route.createOrUpdateRouteSectionDTOList.splice(0, 0, {
          placeId: data.tmsLineInfoParam.originPlaceId,
          placeName: data.tmsLineInfoParam.originPlaceName
        })
        route.createOrUpdateRouteSectionDTOList.push({
          placeId: data.tmsLineInfoParam.destinationPlaceId,
          placeName: data.tmsLineInfoParam.destinationPlaceName
        })
        route.createOrUpdateRouteSectionDTOList.forEach((it, index) => it.sort = (index + 1))
      })
    },

    saveRemote() {
      let data = _.cloneDeep(this.form)
      this.fixSubmitData(data)
      this.submiting = true
      this.$ajax({
        url: '/tms-api/base/TmsLogisticsLineRpc/save.json',
        method: 'post', type: 'json',
        data,
        success: (responseData) => {
          this.$message.success(this.$t('tip_submit_success'))

          this.return_emit(null, "reload")
          this.return_page_back()
        },
        complete: () => {
          this.submiting = false
        }
      });
    },
    updateRemote() {
      let data = _.cloneDeep(this.form)
      this.fixSubmitData(data)
      this.submiting = true
      this.$ajax({
        url: '/tms-api/base/TmsLogisticsLineRpc/update.json',
        method: 'post', type: 'json',
        data,
        success: (responseData) => {
          this.$message.success(this.$t('tip_submit_success'))
          this.return_emit(null, "reload")
          this.return_page_back()
        },
        complete: () => {
          this.submiting = false
        }
      });
    },

  }
};

</script>
<style>
/*途经点配置 */
.manage-path-point-row {
  display: flex;
  flex-wrap: wrap;
}

.manage-path-point-row .manage-path-point-address {
  width: auto;
  padding: 0px 8px;
  position: relative;

}

.cursor_pointer {
  cursor: pointer;
}

.manage-path-point-row .manage-path-point-address .manage-path-point-desc {

  /*border: 1px solid #b3d8ff;*/
  text-align: center;
}

.manage-path-point-row .manage-path-point-address .manage-path-point-desc span {
  color: #409eff;
  border: 1px solid #b3d8ff;
  padding: 2px 4px;
  border-radius: 8px 8px;
}

.manage-path-point-row .manage-path-point-line {
  width: 40px;
  height: 2px;
  border-top: 4px solid #DCDFE6;
  margin-top: 14px;
}

.manage-path-point-row .manage-path-point-arrow {
  width: 0px;
  height: 0px;
  margin-top: 8px;
  border-bottom: 8px solid transparent;
  border-top: 8px solid transparent;
  border-left: 8px solid #DCDFE6;
  font-size: 0;
  line-height: 0;
}

.product-line-limit-div,
.product-line-limit-div-2 {
  display: flex;
}


.product-line-limit-div .product-line-limit-col {
  width: 220px;
  text-align: center;
  margin-right: 10px;
}

.product-line-limit-div-2 div {
  width: 300px;
  /*text-align: center;*/
  margin-right: 10px;
}
</style>
